var conf = require('config.js')

let net = {
    checkNet:function(s,f,c){
        wx.getNetworkType({
            success: function(res) {
                typeof s == "function" && s(res);
            },
            fail:function(res){
                typeof f == "function" && f(res);
            },
            complete:function(res){
                typeof c == "function" && c(res);
            }
        })
    },
    send:function(p){
        let url = conf.server+p.url;

        if(p.showToast){
            wx.showToast({
                title:"连接ing~",
                icon:"loading"
            })
        }

        wx.request({
            url: url,
            data: p.params,
            method: 'GET',
            // header: {},  设置请求的 header
            success: function(res){
                typeof p.success == "function" && p.success(res);
            },
            fail: function(res) {
                typeof p.fail == "function" && p.fail(res);
            },
            complete: function(res) {
                typeof p.complete == "function" && p.complete(res);
                wx.hideToast();
            }
        })
    }
} 

module.exports = net;

